Update Android.bp by running cargo_embargo am: 7e2d5dffbb Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/drm/+/3208873 Change-Id: I5cdd75df9083651e6c3637fd1655c6e1a444a408 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 
tree: ffc98e54175c62971ff1b585734b8b2b4649ffb2
  1. examples/
  2. src/
  3. .cargo_vcs_info.json
  4. Android.bp
  5. Cargo.lock
  6. Cargo.toml
  7. Cargo.toml.orig
  8. cargo_embargo.json
  9. LICENSE
  10. METADATA
  11. MODULE_LICENSE_MIT
  12. OWNERS
  13. README.md
README.md

drm-rs

Crates.io docs.rs Build Status

A safe interface to the Direct Rendering Manager.

Direct Rendering Manager

The Direct Rendering Manager is a subsystem found on multiple Unix-based operating systems that provides a userspace API to graphics hardware. See the Wikipedia article for more details.

Usage

Basic

The DRM is accessed using ioctls on a file representing a graphics card. These can normally be found in /dev/dri, but can also be opened in other ways (ex. udev).

This crate does not provide a method of opening these files. Instead, the user program must provide a way to access the file descriptor representing the device through the AsFd trait. Here is a basic example using File as a backend:

/// A simple wrapper for a device node. pub struct Card(std::fs::File); /// Implementing [`AsFd`] is a prerequisite to implementing the traits found /// in this crate. Here, we are just calling [`File::as_fd()`] on the inner /// [`File`]. impl AsFd for Card { fn as_fd(&self) -> BorrowedFd<'_> { self.0.as_fd() } } /// Simple helper methods for opening a `Card`. impl Card { pub fn open(path: &str) -> Self { let mut options = std::fs::OpenOptions::new(); options.read(true); options.write(true); Card(options.open(path).unwrap()) } } 

Finally, you can implement drm::Device to gain access to the basic DRM functionality:

impl drm::Device for Card {} fn main() { let gpu = Card::open("/dev/dri/card0"); println!("{:#?}", gpu.get_driver().unwrap()); } 

Control (modesetting)

See drm::control::Device as well as our mode-setting examples: atomic_modeset and legacy_modeset

Rendering

Rendering is done by creating and attaching framebuffers to crtcs.

A framebuffer is created from anything implementing Buffer like the always available, but very limited, DumbBuffer.

For faster hardware-backed buffers, checkout gbm.rs.